package com.groupbuying.payproducer.utils;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * @Author gxy
 * @Description java类型转换工具类
 * @Date 2019/4/8 11:22
 **/
public class TypeConvertUtils {

    /**
     * @Author gxy
     * @Description object 转 Bigdecimal
     * @Date 11:23 2019/4/8
     * @Param [value]
     * @return BigDecimal
     **/

    public static BigDecimal getBigDecimal(Object value) {
        BigDecimal ret = null;
        if (value != null) {
            if (value instanceof BigDecimal) {
                ret = (BigDecimal) value;
            } else if (value instanceof String) {
                ret = new BigDecimal((String) value);
            } else if (value instanceof BigInteger) {
                ret = new BigDecimal((BigInteger) value);
            } else if (value instanceof Number) {
                ret = new BigDecimal(((Number) value).doubleValue());
            } else {
                throw new ClassCastException("Not possible to coerce [" + value + "] from class " + value.getClass() + " into a BigDecimal.");
            }
        }
        return ret;
    }

}
